package com.stylefeng.guns.modular.push_msg.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.modular.push_msg.dto.PushNewMsgDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.modular.push_msg.service.IPushMsgService;

/**
 * 消息推送控制器
 *
 * @author fengshuonan
 * @Date 2020-08-04 17:09:57
 */
@Controller
@RequestMapping("/pushMsg")
public class PushMsgController extends BaseController {

    private String PREFIX = "/push_msg/pushMsg/";

    @Autowired
    private IPushMsgService pushMsgService;

    /**
     * 跳转到消息推送首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "pushMsg.html";
    }

    /**
     * 跳转到推送新消息页面
     */
    @RequestMapping("/createNewMsg")
    public String pushMsgAdd() {
        return PREFIX + "pushMsg_edit.html";
    }

    /**
     * 获取消息推送列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "page",defaultValue = "0") Integer page,
                       @RequestParam(value = "limit",defaultValue = "20") Integer limit) {
        return pushMsgService.listMsg(page,limit);
    }

    /**
     * 创建并推送消息
     * @param pushMsgDTO
     * @return
     */
    @RequestMapping("/sendMsg")
    @ResponseBody
    public Object sendMsg(PushNewMsgDTO pushMsgDTO){
        pushMsgService.pushMsg(pushMsgDTO);
        return SUCCESS_TIP;
    }
}
